package com.itita.ww2.handler.requesthandler.user;

import java.sql.SQLException;

import com.itita.ww2.core.MessageHandler;
import com.itita.ww2.core.WW2Exception;
import com.itita.ww2.enums.AreaEnum;
import com.itita.ww2.game.user.UserService;
import com.itita.ww2.model.area.AreaCity;
import com.itita.ww2.model.area.AreaDefault;
import com.itita.ww2.model.area.AreaWorldMap;
import com.itita.ww2.model.user.UserProfile;
import com.itita.ww2.utils.handler.IRequestOper;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;

/**
 * 玩家进入某区域
 * @author NorthLan
 *
 */
public class EnterArea implements IRequestOper {
	// 区域ID对应

	@Override
	public boolean execute(String requestCMD, User user, ISFSObject params) throws WW2Exception, SQLException {
		UserProfile userProfile = UserService.getInstance().getUserProfile(user);
		int areaId = params.getInt("areaId");
		AreaEnum area = AreaEnum.valueOf(areaId);

		switch (area) {
		case WORLDMAP:
			userProfile.setCurArea(new AreaWorldMap());
			break;
		case CITY:
			int blockId = params.getInt("blockId");
			int cityId = params.getInt("cityId");
			userProfile.setCurArea(new AreaCity(blockId, cityId));
			break;
		case AL_BF:
			//			int bfId = params.getInt("bfId");
			//			// 盟战开启情况
			//			ISFSObject config = AllianceBattleDataManager.getInstance().loadConfig();
			//			if (!config.getBool("enable")) {
			//				MessageHandler.getInstance().sendMsg(requestCMD, null, user, MsgCode.ALLIANCE_BATTLE_NOT_ENABLE, false);
			//				return false;
			//			}
			//			// 检查战场存在情况
			//			if (!AllianceBattleDataManager.getInstance().checkBFExist(bfId)) {
			//				MessageHandler.getInstance().sendMsg(requestCMD, null, user, MsgCode.ALLIANCE_BATTLE_BF_NOT_FOUND,
			//						false);
			//				return false;
			//			}
			//			userProfile.setCurArea(new AreaAlBf(bfId));
			break;
		default:
			userProfile.setCurArea(new AreaDefault());
			break;
		}
		// 返回true 表示能进入该区域
		MessageHandler.getInstance().sendMsg(requestCMD, null, user, null, true);
		return true;
	}

}
